﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using FireStarter.Base;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using Habanero.Base;
using Habanero.BO;
using Habanero.Console;

namespace FireStarterModeller.WPF
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        private void Application_Startup(object sender, StartupEventArgs e)
        {

            HabaneroAppWPF app = new HabaneroAppWPF("FireStarterModeller.WPF", "0.0001");
            app.ClassDefsXml = BOBroker.GetClassDefsXml();
            
            app.UseDatabase = false;
            app.Startup();

            GlobalRegistry.UIExceptionNotifier = new WPFUIExceptionNotifier();

            DMSolution solution = TestUtilsShared.CreateSavedDMSolution();
            solution.DefaultAssembly.CreateClass("TestClass1");
            solution.DefaultAssembly.CreateClass("TestClass2");
            DMAssembly assembly2 = solution.CreateAssembly("TestAssembly2");
            assembly2.CreateClass("TestClass3");
            solution.Save();
        }


        private class HabaneroAppWPF : HabaneroAppConsole
        {
            public HabaneroAppWPF(string appName, string appVersion)
                : base(appName, appVersion)
            {
            }

            public bool UseDatabase { get; set; }

            protected override void SetupDatabaseConnection()
            {
                if (UseDatabase) base.SetupDatabaseConnection(); else BORegistry.DataAccessor = new DataAccessorInMemory();
            }
        }
    }

    internal class WPFUIExceptionNotifier : IExceptionNotifier {
        public void Notify(Exception ex, string furtherMessage, string title) {
            MessageBox.Show(furtherMessage + ":" + Environment.NewLine + ex.Message, title);
        }
        public string ExceptionMessage { get { return ""; } }
    }
}
